package com.cs.user.domain.service.impl;

import com.cs.user.common.entity.ErrorCode;
import com.cs.user.common.utlis.ThrowUtils;
import com.cs.user.domain.bos.RoleBO;
import com.cs.user.domain.service.RoleDomainService;
import com.cs.user.infra.basic.entity.Role;
import com.cs.user.infra.basic.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RoleDomainServiceImpl implements RoleDomainService {

    @Resource
    private RoleService roleService;

    @Override
    public Boolean addRole(RoleBO roleBO) {
        // 参数校验
        ThrowUtils.throwIf(roleBO.getRoleName() == null, ErrorCode.PARAMS_ERROR,"角色名呢？");
        // 类型转换
        Role role = new Role();
        BeanUtils.copyProperties(roleBO, role);
        // 调用infra层方法
        return roleService.addRole(role);
    }

    @Override
    public Boolean deleteRole(RoleBO roleBO) {
        // 参数校验
        ThrowUtils.throwIf(roleBO.getBusinessId() == null, ErrorCode.PARAMS_ERROR,"角色id呢？");
        // 类型转换
        Role role = new Role();
        BeanUtils.copyProperties(roleBO, role);
        // 调用infra层方法
        return roleService.deleteRole(role);
    }

    @Override
    public Boolean updateRole(RoleBO roleBO) {
        // 参数校验
        ThrowUtils.throwIf(roleBO.getBusinessId() == null, ErrorCode.PARAMS_ERROR,"角色id呢？");
        // 类型转换
        Role role = new Role();
        BeanUtils.copyProperties(roleBO, role);
        // 调用infra层方法
        return roleService.updateRole(role);
    }
}
